package com.sms.dao.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.sms.dao.IOperlogDAO;
import com.sms.po.Operlog;

/**
 * @author 20111012 by cxh
 */
public class OperlogDAO extends HibernateDaoSupport implements IOperlogDAO {
	private static final Log log = LogFactory.getLog(OperlogDAO.class);

	@Override
	public List<Operlog> showAllOperlog() {
		log.debug("finding all Operlog instances");
		try{
			return super.getHibernateTemplate().find("from Operlog");
		}catch(RuntimeException e){
			log.debug("finding all failed:",e);
			throw e;
		}
	}

	@Override
	public List<Operlog> showAllOperlogByPage(DetachedCriteria criteria, int start,int limit) {
		log.debug("finding all Operlog by pages");
		try{
			return super.getHibernateTemplate().findByCriteria(
					criteria, start, limit);
		}catch(RuntimeException e){
			log.debug("finding all Operlog failed:",e);
			throw e;
		}
	}

	@Override
	public int getAllOperlogCount(DetachedCriteria criteria) {
		return super.getHibernateTemplate().findByCriteria(criteria).size();
	}

	@Override
	public boolean addOperlog(Operlog ol) {
		log.debug("add Operlog instance...");
		try{
			log.debug("add Operlog instance success");
			this.getHibernateTemplate().save(ol);
			return true;
		}catch(RuntimeException e){
			log.debug("add Operlog instance failed:",e);
			throw e;
		}
	}


}
